﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sales_Contract_View.aspx.cs" Inherits="JKF.Web.Sales.Contract.Sales_Contract_View" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <%= RegScript("~/js/jquery.1.5.js")%>
    <%= RegScript("~/js/jquery.nhis.js")%>
    <%= RegScript("~/js/jquery.rchis.js")%>
    <%= RegScript("~/js/jquery-ui-custom.min.js")%>
    <%= RegScript("~/js/css.js")%>
    <%= RegScript("~/js/Common.js")%>
    <%= RegScript("~/js/Jquery.commonGrid.js")%>

    <%= RegScript("~/js/jquery.json.js")%>
    <%= RegScript("~/js/jquery.validate.js")%>
    <%= RegScript("~/js/DatePicker/WdatePicker.js")%>
    <%=this.RegStyle("~/App_Themes/Theme2/Include.css")%>
    <%= RegScript("~/js/jquery-form.js") %>
    <script type="text/javascript">
        var AppPath = '<%=AppPath %>';
        var handler = AppPath + '/do/Sales/Sales_Contract.do';
        var tmpl = new DTemplate();
        var shops = <%=Shops%>;
        var PageSize = 20;
        var pager = null;
        var rowTemplate = "<tr pk=\"${CONTRACT_KEY}\"><td><input type=\"button\" style=\"display:${EDITSHOW};\" class=\"op-edit common_btn_edit mr12\" value=\"\"/><input type=\"button\" style=\"display:${DELETESHOW};\" class=\"op-del common_btn_del mr12\" /></td><td>${CARD_NO}</td><td>${CUSTOMER_NAME}</td><td>${MOBILE}</td><td>${PHONE}</td><td>${UNIQUE_CODE}</td><td>${CONTRACT_CODE}</td><td>${PRODUCT_NAME}</td><td>${MODEL}</td><td>${PRICE}</td><td>${MONEY}</td><td>${BURNDATE}</td><td>${REPAIR_TERM}</td><td>${DATE_PURCHASE}</td><td>${CLOSING_DATE}</td><td>${STATUS}</td><td>${OPERATOR}</td><td>${DATE_CREATE}</td></tr>";
        var dtReg = /^\d{4}(\/|-)([1][0-2]|[1-9]|0[1-9])(\/|-)([1-2][0-9]|3[0-1]|[1-9]|0[1-9])( (0?[0-9]|1[0-9]|2[0-4])(:([0-5][0-9])){1,2})?$/;
        $(function () {
            BindValidate();
            pager = $('#divPager').pager(AppPath, handler, function () {
                return {
                    ActionName: 'GetContractByPage',
                    schOptions: $.toJSON({
                        DATE_PURCHASESTART: $.FxNull($("#DATE_PURCHASESTART").val(), ""),
                        DATE_PURCHASEEND: $.FxNull($("#DATE_PURCHASEEND").val(), ""),
                        STATE:"1",
                        SHOP_CODE: $.FxNull($("#ownShop").attr("codes"), ""),
                        filterBy: $.FxNull($("#filterBy").val(), ""),
                        filterOperater: $.FxNull($("#filterOperater").val(), ""),
                        fiterText: $.FxNull($("#fiterText").val(), "")
                    })
                };
            }, function (data) {
                var tbody = $('#tb tbody');
                tbody.empty();
                if (data && data.Entity && data.Entity.length) {
                    Permission(data.Entity);
                    tbody.html(tmpl(rowTemplate, data.Entity, true));
                } else {
                    tbody.html('<tr><td colspan="18" style="text-align: center">没有数据!</td></tr>');
                }
                $("#tb").H8_Grid($("#divPager"), (function (){var tbHeight = $(window).height()-35; tbHeight-=($(".common_search").size()>0)?$(".common_search").eq(0).height():0; tbHeight-=($("#divPager").size()>0)?$("#divPager").height():0; return tbHeight < 300 ? 300 : tbHeight;})());
            }, PageSize, true);
            BindGridEvent();

            $('#btnSearch').click(function () {
                if (!$.validateAll()) {
                    if ($(".alxv-failed").size() > 0) {
                        $(document).scrollTop($(".alxv-failed").eq(0).scrollTop());
                    }
                    return;
                };
                pager.option.pageIndex = 1;
                pager.getPegerData();
                return false;
            });
            $("#ownShop").MgrShopSelect(AppPath,shops);
            
            $("#btnExport").click(function() {
                var obj ={
                    ActionName: 'GetContractByPage',
                    schOptions: $.toJSON({
                        DATE_PURCHASESTART: $.FxNull($("#DATE_PURCHASESTART").val(), ""),
                        DATE_PURCHASEEND: $.FxNull($("#DATE_PURCHASEEND").val(), ""),
                        STATE:"1",
                        SHOP_CODE: $.FxNull($("#ownShop").attr("codes"), ""),
                        filterBy: $.FxNull($("#filterBy").val(), ""),
                        filterOperater: $.FxNull($("#filterOperater").val(), ""),
                        fiterText: $.FxNull($("#fiterText").val(), "")
                    }),
                    isExport:1,
                    PageIndex:pager.option.pageIndex ,
                    PageSize:pager.option.pageSize};
                $.formP(handler, obj);
            });

        });
        function BindGridEvent() {
            $(':button.op-del').live('click', function () {
                if (!confirm("确认删除吗?")) return false;
                var tr = $(this).parent().parent();
                $.post(handler, { ActionName: 'RemoveSalesContract', constractKey: tr.attr('pk') }, function (obj) {
                    if (!obj.Success) alert(obj.Message);
                    else {
                        reduceCount();//减少记录总条数
                        tr.remove();}
                }, "json");
            });
            $(':button.op-edit').live('click', function () {
                window.parent.pop("编辑销售合同", '<%= ResolveUrl("~/Sales/Contract/Sales_Contract_Add.aspx?contractKey=") %>' + $(this).parent().parent().attr("pk"), 860, 500, updateList);
            });
        }

        //弹出层
        function Add(id) { window.parent.pop("添加销售合同", '<%= ResolveUrl("~/Sales/Sales_Product_Add.aspx?module=contract") %>', 890, 500, updateList); };

        function updateList(obj) {
            var tbody = $('#tb tbody');
            var key = $.FxNull(obj.CONTRACT_KEY, "");
            if (tbody.find("tr[pk]").size() == 0) tbody.empty();
            if (key == "") return;
            Permission(obj);
            var editRow = tbody.find("tr[pk='" + key + "']");
            var newRow = $(tmpl(rowTemplate, obj, true));
            if (editRow.size() == 0) {
                tbody.prepend(newRow);
                addCount(); //添加成功之后更新记录总条数
            } else {
                newRow.insertAfter(editRow);
                editRow.remove();
            }
            $("#tb").H8_Grid($("#divPager"), (function (){var tbHeight = $(window).height()-35; tbHeight-=($(".common_search").size()>0)?$(".common_search").eq(0).height():0; tbHeight-=($("#divPager").size()>0)?$("#divPager").height():0; return tbHeight < 300 ? 300 : tbHeight;})());
            //BindGridEvent();
        }

        function BindValidate() {
            alxVr.push({
                id: "DATE_PURCHASESTART",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl.length > 0 && !dtReg.test(vl)) {
                        this.msg = "购买起始日期格式不正确.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "DATE_PURCHASEEND",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl.length > 0 && !dtReg.test(vl)) {
                        this.msg = "购买截止日期格式不正确.";
                        return false;
                    }
                    var stvl = $.trim($("#DATE_PURCHASESTART").val());
                    if (stvl.length > 0 && dtReg.test(stvl)) {
                        if ($.DateCompare(stvl, vl) > 0) {
                            this.msg = "购买截止日期应大于等于购买起始日期.";
                            return false;
                        }
                    }
                    return true;
                }
            });
            $.validateBind();
        }
        function Permission(data) {
            var permissionEdit = "<%=DispEdit%>";
            var permissionDel = "<%=DispDelete%>";
            if($.isArray(data)){
                $(data).each(function() {
                    this.EDITSHOW = (this.EDITSHOW == "none") ? this.EDITSHOW:permissionEdit;
                    this.DELETESHOW=(this.EDITSHOW == "none") ? this.EDITSHOW:permissionDel;
                });
                return;
            }
            if (!data.hasOwnProperty("EDITSHOW")) data.EDITSHOW = "";
            data.EDITSHOW = (this.EDITSHOW == "none") ? this.EDITSHOW:permissionEdit;
            data.DELETESHOW=(this.EDITSHOW == "none") ? this.EDITSHOW:permissionDel;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="warrper_body">
            <div class="index">
                <div class="common_search">
                    <div class="l_h45">
                        <span class="mr30 mb20">查询项：
                            <select id="filterBy" class="common_search_select w100">
                                <option value="card_no">会员卡号</option>
                                <option value="customer_name">顾客姓名</option>
                                <option value="mobile">顾客手机</option>
                                <option value="unique_code" selected="selected">销售单号</option>
                                <option value="contract_code">合同编号</option>
                                <option value="date_purchase">生产日期</option>
                                <option value="product_name">产品名称</option>
                                <option value="model">产品型号</option>
                                <option value="memo">销售备注</option>
                                <option value="operator">操作员</option>
                            </select>
                            <select id="filterOperater" class="common_search_select w100">
                                <option value="like">包含</option>
                                <option value="=">=</option>
                            </select>
                            <input id="fiterText" type="text" class="common_search_input w100" /></span>

                        <span class="mr30 mb20">店铺：
                            <input type="button" id="ownShop" class="common_btn_gaoji115" />
                        </span>
                        <span class="mr30 mb20">购买日期：
                            <input id="DATE_PURCHASESTART" type="text" onfocus="WdatePicker()" class="common_search_input w100" />

                            至
                            <input id="DATE_PURCHASEEND" type="text" onfocus="WdatePicker()" class="common_search_input w100" />
                        </span>
                        <%--<span class="mr30 mb20">状态：
                            <select id="STATE">
                                <option value="1">有效</option>
                                <option value="9">无效</option>
                                <option value="">全部</option>
                            </select>
                        </span>--%>

                        <input id="btnSearch" type="button" value="" class="common_btn_search" />
                        <input id="btnAdd" type="button" value="" onclick="Add()" class="common_btn_add2" style="display: <%=DispAdd%>;" />
                        <input id="btnExport" type="button" value="导出Excel" class="btn_style" />
                    </div>
                </div>
                <div class="l_h7"></div>
                <div class="index_table">
                    <table id="tb" class="common_table">
                        <thead>
                            <tr>
                                <th width="100px" orderaction="false">操作</th>
                                <th width="100px" ordertype="string">顾客卡号</th>
                                <th width="100px" ordertype="string">姓名</th>
                                <th width="100px" ordertype="string">手机</th>
                                <th width="100px" ordertype="string">电话号码</th>
                                <th width="170px" ordertype="string">销售单号</th>
                                <th width="100px" ordertype="string">合同编号</th>
                                <th width="100px" ordertype="string">产品名称</th>
                                <th width="100px">产品型号</th>
                                <th width="100px" ordertype="string">价格</th>
                                <th width="100px" ordertype="string">实收金额</th>
                                <th width="100px" ordertype="string">生产日期</th>
                                <th width="100px" ordertype="string">保修期限</th>
                                <th width="100px" ordertype="string">购买日期</th>
                                <th width="150px" ordertype="string">保修截止日期</th>
                                <th width="100px" ordertype="string">状态</th>
                                <th width="100px" ordertype="string">操作员</th>
                                <th width="100px" ordertype="string">入库日期</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td colspan="18" style="text-align: center">点击搜索查看数据
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="page" id="divPager">
                </div>
            </div>
        </div>
    </form>
</body>
</html>
